#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;

class File
{
private:      // 私有的
    FILE *pf; // 文件指针
    char name[20];
    char type[20];
    char content[100]; // 内容

public: // 公有的
    bool fcreate(const char *pFileName)
    {
        pf = fopen(pFileName, "w");
        return pf != NULL;
    }

    bool open(const char *pFileName, const char *pMode)
    {
        pf = fopen(pFileName, pMode);
        if (pf == NULL)
        {
            cout << "打开文件失败！" << endl;
            return false;
        }
        return true;
    }
    void close()
    {
        if (pf != NULL)
        {
            fclose(pf);
            pf = NULL;
        }
    }
    void write(const char *pContent)
    {
        if (pf != NULL)
        {
            fputs(pContent, pf);
        }
    }
    void read()
    {
        if (pf != NULL)
        {
            while (fgets(content, 100, pf) != NULL)
            {
                cout << content;
            }
        }
    }
};

int main(int argc, char const *argv[])
{
    File f;
    
    if (f.fcreate("test.txt"))
    {
        if (f.open("test.txt", "w"))
        {
            f.write("hello world!\n");
            f.close();
        }
    }
    if (f.open("test.txt", "r"))
    {
        f.read();
        f.close();
    }
    return 0;
}
